package com.shouhuobao.take.mine;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shouhuobao.station.R;
import com.shouhuobao.take.model.ShopInfoBean;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterWithImage;

/**
 * Created by joker on 2017/9/11.
 * 物料下载适配器
 */
public class ShopInfoDownAdapter extends BaseAdapterWithImage<ShopInfoBean> {

    public ShopInfoDownAdapter(ArrayList<ShopInfoBean> items, Activity context, ViewGroup listView) {
        super(items, context, listView);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_shop_info_down, parent, false);
            holder.titleTV = (TextView) convertView.findViewById(R.id.title_tv);
            holder.downTV = (TextView) convertView.findViewById(R.id.down_tv);
            holder.detailTV = (TextView) convertView.findViewById(R.id.detail_tv);
            holder.shopImageIV = (ImageView) convertView.findViewById(R.id.shop_image_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final ShopInfoBean shopInfoBean = getItem(position);
        holder.titleTV.setText(shopInfoBean.getShopTitle());
        holder.detailTV.setText("使用场景：" + shopInfoBean.getShopDescription());
        holder.shopImageIV.setImageResource(shopInfoBean.getShopImageUrl());
        holder.downTV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ShopInfoDownActivity) context).downShopImage(shopInfoBean.getType());
            }
        });
        return convertView;
    }

    class ViewHolder {
        TextView titleTV;// 物料下载标题
        TextView downTV;// 物料下载
        TextView detailTV;// 使用场景描述
        ImageView shopImageIV;
    }
}
